﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.Base;
using UFIDA.U9.Base.Doc;
using UFIDA.U9.Base.FlexField.ValueSet;
using UFIDA.U9.Base.UserRole;
using UFIDA.U9.CBO.SCM.ProjectTask;
using UFIDA.U9.Cust.YYD.PlugBE.Dtos;
using UFIDA.U9.Cust.YYD.PlugBE.Public;
using UFIDA.U9.MO.Exceptions;
using UFIDA.U9.PM.PO;
using UFIDA.U9.PPR.PurPriceList;
using UFSoft.UBF.Business;
using UFSoft.UBF.Util.DataAccess;

namespace UFIDA.U9.Cust.YYD.PlugBE.PurchaseOrderP
{
    public class AfterUpdating : UFSoft.UBF.Eventing.IEventSubscriber
    {
        public void Notify(params object[] args)
        {
            #region 从事件参数中取得当前业务实体													 
            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
                return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;
            if (key == null)
                return;
            var holder = key.GetEntity() as UFIDA.U9.PM.PO.PurchaseOrder;
            if (holder == null)
                return;
            #endregion

            HttpHelper httpHelper = new HttpHelper();
            JsonConfig config = new JsonConfig();
            //委外提交传WMS
            if (holder.DocumentType.BusinessType == BusinessTypeEnum.PM055 && holder.Status == PM.PO.PODOCStatusEnum.Approved && holder.OriginalData.Status != PM.PO.PODOCStatusEnum.Approved)
            {
                httpHelper.URL = config.SelectToken("WMS.URL") + "/openapi/erpPoSync/save";
                var json = POServices.TransWMSDTO(holder);
                httpHelper.Content = JsonConvert.SerializeObject(json);
                var result = JObject.Parse(httpHelper.HttpPosts("POST"));
                if (result["code"].ToString() != "000000")
                {
                    throw new Exception(result["msg"].ToString());
                }
            }
            //委外反审核传WMS删除
            else if (holder.DocumentType.BusinessType == BusinessTypeEnum.PM055 && holder.Status == PM.PO.PODOCStatusEnum.Opened && holder.OriginalData.Status != PM.PO.PODOCStatusEnum.Opened)
            {
                httpHelper.URL = config.SelectToken("WMS.URL") + "/openapi/erpPoSync/delete";
                var json = new
                {
                    orderNo = holder.DocNo
                };
                httpHelper.Content = JsonConvert.SerializeObject(json);
                var result = JObject.Parse(httpHelper.HttpPosts("POST"));
                if (result["code"].ToString() != "000000")
                {
                    throw new Exception(result["msg"].ToString());
                }
            }
            else if (holder.DocumentType.BusinessType == BusinessTypeEnum.PM055 && holder.Status == PM.PO.PODOCStatusEnum.Approved)
            {
                if (POServices.IsChange(holder.OriginalData, holder, out WMSPODTO json))
                {
                    httpHelper.URL = config.SelectToken("WMS.URL") + "/openapi/erpPoSync/update";
                    httpHelper.Content = JsonConvert.SerializeObject(json);
                    var result = JObject.Parse(httpHelper.HttpPosts("POST"));
                    if (result["code"].ToString() != "000000")
                    {
                        throw new Exception(result["msg"].ToString());
                    }
                }
            }

            //提交传OA
            if (holder.OriginalData.Status == PM.PO.PODOCStatusEnum.Opened && holder.Status == PM.PO.PODOCStatusEnum.Approving)
            {

                string workflowId = string.Empty;
                string formId = string.Empty;
                string subFormId = string.Empty;
                switch (holder.DocumentType.Code)
                {
                    case "PO01"://研发工程采购订单
                        workflowId = "1203299980855427073";
                        formId = "1203299980855427484";
                        subFormId = "1203299980855427555";
                        break;
                    case "PO02"://MRP请购采购订单
                        workflowId = "1203300496209559552";
                        formId = "1203300496209560056";
                        subFormId = "1203300496209560038";
                        break;
                    case "PO03"://生产采购订单
                        workflowId = "1203300689441144832";
                        formId = "1203300689441145247";
                        subFormId = "1203300689441145318";
                        break;
                    case "PO04"://部门采购订单
                        workflowId = "1203302437610274817";
                        formId = "1203302441871688089";
                        subFormId = "1203302441871688160";
                        break;
                    case "PO05"://模具资产采购订单
                        workflowId = "1203300938515693570";
                        formId = "1203300938515693985";
                        subFormId = "1203300938515694056";
                        break;
                    case "PO07"://固定资产采购订单
                        workflowId = "1203301101799948296";
                        formId = "1203301101799948711";
                        subFormId = "1203301101799948782";
                        break;
                    case "PO08"://换铜采购订单
                        workflowId = "1203301222084198402";
                        formId = "1203301222084198817";
                        subFormId = "1203301222084198888";
                        break;
                    case "PO09"://无氧铜采购订单
                        workflowId = "1203301372273836032";
                        formId = "1203301372273836447";
                        subFormId = "1203301372273836518";
                        break;
                    case "PO11"://费用/服务采购订单
                        workflowId = "1203301518428553217";
                        formId = "1203301522706743315";
                        subFormId = "1203301522706743386";
                        break;
                    case "PO10"://全程委外订单
                        workflowId = "1203301621423882242";
                        formId = "1203301621423882657";
                        subFormId = "1203301621423882728";
                        break;
                    case "PO98"://期初全程委外订单
                        workflowId = "1203301728705789952";
                        formId = "1203301728705790367";
                        subFormId = "1203301728705790438";
                        break;
                }

                if (string.IsNullOrEmpty(workflowId))
                {
                    return;
                }

                //新增
                if (string.IsNullOrEmpty(holder.DescFlexField.PrivateDescSeg1))
                {
                    var token = httpHelper.GetOAToken();
                    httpHelper.URL = config.SelectToken("OA.URL") + "/papi/openapi/api/workflow/core/paService/v1/doCreateRequest";

                    User user = User.Finder.FindByID(Context.LoginUserID);
                    var userinfo = httpHelper.GetOAUserInfo(token, user.Code);




                    OADTO dto = new OADTO();
                    dto.access_token = token;
                    dto.userid = userinfo.Key;
                    dto.workflowId = workflowId;
                    var formData = new FormData();
                    formData.formId = formId;
                    var dataDetails = new List<DataDetailsItem>();



                    //申请人
                    DataDetailsItem d1 = new DataDetailsItem();
                    d1.dataOptions = new List<DataOptionsItem> {new DataOptionsItem{
                        content = Context.LoginUser,
                        optionId = userinfo.Key,
                        type ="resource"
                    }};
                    d1.dataKey = "sqr";
                    dataDetails.Add(d1);

                    //申请部门
                    DataDetailsItem d2 = new DataDetailsItem();
                    d2.dataOptions = new List<DataOptionsItem> {new DataOptionsItem{
                        content="",
                        optionId= userinfo.Value,
                        type="department"
                    }};
                    d2.dataKey = "sqbm";
                    dataDetails.Add(d2);

                    //推送日期
                    DataDetailsItem d3 = new DataDetailsItem();
                    d3.content = DateTime.Now.Date.ToShortDateString();
                    d3.dataKey = "tsrq";
                    dataDetails.Add(d3);

                    //单据类型
                    DataDetailsItem d4 = new DataDetailsItem();
                    d4.content = holder.DocumentType.Name;
                    d4.dataKey = "djlx";
                    dataDetails.Add(d4);

                    //供应商名称
                    DataDetailsItem d5 = new DataDetailsItem();
                    d5.content = holder.Supplier.Name; ;
                    d5.dataKey = "gysmc";
                    dataDetails.Add(d5);

                    //单据日期
                    DataDetailsItem d6 = new DataDetailsItem();
                    d6.content = holder.BusinessDate.ToShortDateString();
                    d6.dataKey = "djrq";
                    dataDetails.Add(d6);

                    //币种
                    DataDetailsItem d7 = new DataDetailsItem();
                    d7.content = holder.TC.Name;
                    d7.dataKey = "bz";
                    dataDetails.Add(d7);


                    //流程编号
                    DataDetailsItem d8 = new DataDetailsItem();
                    d8.content = holder.DocNo;
                    d8.dataKey = "lcbh";
                    dataDetails.Add(d8);

                    //立账条件
                    DataDetailsItem d9 = new DataDetailsItem();
                    d9.content = holder.ConfirmTerm?.Name ?? "";
                    d9.dataKey = "lztj";
                    dataDetails.Add(d9);

                    //业务员
                    DataDetailsItem d10 = new DataDetailsItem();
                    d10.content = holder.PurOper?.Name??"";
                    d10.dataKey = "ywy";
                    dataDetails.Add(d10);

                    //部门
                    DataDetailsItem d11 = new DataDetailsItem();
                    d11.content = holder.PurDept?.Name??"";
                    d11.dataKey = "bm";
                    dataDetails.Add(d11);


                    //厂商价目表
                    PurPriceList purPriceList = PurPriceList.Finder.FindByID(holder.PriceList);
                    DataDetailsItem d12 = new DataDetailsItem();
                    d12.content = purPriceList?.Name??"";
                    d12.dataKey = "csjmb";
                    dataDetails.Add(d12);

                    //税组合
                    DataDetailsItem d13 = new DataDetailsItem();
                    d13.content = holder.TaxSchedule?.Name ?? "";
                    d13.dataKey = "szh";
                    dataDetails.Add(d13);

                    //收货原则
                    DataDetailsItem d14 = new DataDetailsItem();
                    d14.content = holder.ReceiptRule?.Name ?? "";
                    d14.dataKey = "shyz";
                    dataDetails.Add(d14);

                    //价格含税
                    DataDetailsItem d15 = new DataDetailsItem();
                    d15.content = holder.IsPriceIncludeTax ? "0" : "1";
                    d15.dataKey = "jghs";
                    dataDetails.Add(d15);


                    foreach (var line in holder.POLines)
                    {
                        //来源类别
                        string sql = $@" select dbo.F_GetEnumName('UFIDA.U9.PM.Enums.POSrcDocTypeEnum','{line.SrcDocType.Value}','zh-CN') POSrcDocTypeEnum";
                        DataAccessor.RunSQL(DataAccessor.GetConn(), sql, null, out DataSet ds);
                        string POSrcDocTypeEnum = ds.Tables[0].Rows[0]["POSrcDocTypeEnum"].ToString();
                        DataDetailsItem it1 = new DataDetailsItem();
                        it1.content = POSrcDocTypeEnum;
                        it1.dataIndex = line.DocLineNo / 10;
                        it1.dataKey = "lylb";
                        it1.subFormId = subFormId;
                        dataDetails.Add(it1);

                        //来源单号
                        DataDetailsItem it2 = new DataDetailsItem();
                        it2.content = line.SrcDocInfo?.SrcDocNo??"";
                        it2.dataIndex = line.DocLineNo / 10;
                        it2.dataKey = "lydh";
                        it2.subFormId = subFormId;
                        dataDetails.Add(it2);

                        //送货地址
                        DataDetailsItem it3 = new DataDetailsItem();
                        it3.content = DefineValue.Finder.Find($"ValueSetDef.Code = 'Z006' and Code = '{line.DescFlexSegments.PubDescSeg2}'")?.Name ?? "";
                        it3.dataIndex = line.DocLineNo / 10;
                        it3.dataKey = "shdz";
                        it3.subFormId = subFormId;
                        dataDetails.Add(it3);

                        //赠品
                        DataDetailsItem it4 = new DataDetailsItem();
                        it4.content = line.IsPresent ? "0" : "1";
                        it4.dataIndex = line.DocLineNo / 10;
                        it4.dataKey = "zp";
                        it4.subFormId = subFormId;
                        dataDetails.Add(it4);

                        //料号
                        DataDetailsItem it5 = new DataDetailsItem();
                        it5.content = line.ItemInfo.ItemID.Code;
                        it5.dataIndex = line.DocLineNo / 10;
                        it5.dataKey = "lh";
                        it5.subFormId = subFormId;
                        dataDetails.Add(it5);


                        //品名
                        DataDetailsItem it6 = new DataDetailsItem();
                        it6.content = line.ItemInfo.ItemID.Name;
                        it6.dataIndex = line.DocLineNo / 10;
                        it6.dataKey = "pm";
                        it6.subFormId = subFormId;
                        dataDetails.Add(it6);


                        //项目
                        DataDetailsItem it7 = new DataDetailsItem();
                        it7.content = line.Project?.Name??"";
                        it7.dataIndex = line.DocLineNo / 10;
                        it7.dataKey = "xm";
                        it7.subFormId = subFormId;
                        dataDetails.Add(it7);

                        //需求数量
                        DataDetailsItem it8 = new DataDetailsItem();
                        it8.content = line.ReqQtyTU.ToString();
                        it8.dataIndex = line.DocLineNo / 10;
                        it8.dataKey = "xqsl";
                        it8.subFormId = subFormId;
                        dataDetails.Add(it8);

                        //采购数量
                        DataDetailsItem it9 = new DataDetailsItem();
                        it9.content = line.PurQtyTU.ToString();
                        it9.dataIndex = line.DocLineNo / 10;
                        it9.dataKey = "cgsl";
                        it9.subFormId = subFormId;
                        dataDetails.Add(it9);

                        //采购单位
                        DataDetailsItem it10 = new DataDetailsItem();
                        it10.content = line.TradeUOM.Name;
                        it10.dataIndex = line.DocLineNo / 10;
                        it10.dataKey = "cgdw";
                        it10.subFormId = subFormId;
                        dataDetails.Add(it10);

                        //计价单位
                        DataDetailsItem it11 = new DataDetailsItem();
                        it11.content = line.PriceUOM.Name;
                        it11.dataIndex = line.DocLineNo / 10;
                        it11.dataKey = "jjdw";
                        it11.subFormId = subFormId;
                        dataDetails.Add(it11);

                        //交期
                        DataDetailsItem it12 = new DataDetailsItem();
                        it12.content = line.POShiplines[0]?.DeliveryDate.ToShortDateString()??"";
                        it12.dataIndex = line.DocLineNo / 10;
                        it12.dataKey = "jq";
                        it12.subFormId = subFormId;
                        dataDetails.Add(it12);

                        //最终价原币
                        DataDetailsItem it13 = new DataDetailsItem();
                        it13.content = line.FinallyPriceTC.ToString();
                        it13.dataIndex = line.DocLineNo / 10;
                        it13.dataKey = "zzjyb";
                        it13.subFormId = subFormId;
                        dataDetails.Add(it13);

                        //价税合计原币
                        DataDetailsItem it14 = new DataDetailsItem();
                        it14.content = line.TotalMnyTC.ToString();
                        it14.dataIndex = line.DocLineNo / 10;
                        it14.dataKey = "sjhjyb";
                        it14.subFormId = subFormId;
                        dataDetails.Add(it14);

                        //未税金额原币
                        DataDetailsItem it15 = new DataDetailsItem();
                        it15.content = line.NetMnyTC.ToString();
                        it15.dataIndex = line.DocLineNo / 10;
                        it15.dataKey = "wsjeyb";
                        it15.subFormId = subFormId;
                        dataDetails.Add(it15);

                        //税额原币
                        DataDetailsItem it16 = new DataDetailsItem();
                        it16.content = line.TotalTaxTC.ToString();
                        it16.dataIndex = line.DocLineNo / 10;
                        it16.dataKey = "seyb";
                        it16.subFormId = subFormId;
                        dataDetails.Add(it16);

                        //存储地点
                        DataDetailsItem it17 = new DataDetailsItem();
                        it17.content = line.POShiplines[0]?.Wh?.Name ?? "";
                        it17.dataIndex = line.DocLineNo / 10;
                        it17.dataKey = "ccdd";
                        it17.subFormId = subFormId;
                        dataDetails.Add(it17);

                        //贸易路径
                        DataDetailsItem it18 = new DataDetailsItem();
                        it18.content = line.TradePath?.Name??"";
                        it18.dataIndex = line.DocLineNo / 10;
                        it18.dataKey = "mylj";
                        it18.subFormId = subFormId;
                        dataDetails.Add(it18);

                    }

                    formData.dataDetails = dataDetails;
                    dto.formData = formData;
                    dto.otherParams = new OtherParams { isnextflow = "1" };
                    httpHelper.Content = JsonConvert.SerializeObject(dto);
                    var result = JObject.Parse(httpHelper.HttpPosts("POST"));
                    if (result["message"]["errmsg"].ToString() != "success")
                    {
                        throw new Exception(result["message"]["errmsg"].ToString());
                    }

                    holder.DescFlexField.PrivateDescSeg1 = result["message"]["requestId"].ToString();
                }
                else
                {
                  
                    var token = httpHelper.GetOAToken();
                    httpHelper.URL = config.SelectToken("OA.URL") + "/papi/openapi/api/workflow/core/paService/v1/submitRequest";

                    User user = User.Finder.FindByID(Context.LoginUserID);
                    var userinfo = httpHelper.GetOAUserInfo(token, user.Code);

                    OAUpdateDTO dto = new OAUpdateDTO();
                    dto.access_token = token;
                    dto.userid = userinfo.Key;
                    dto.requestId = holder.DescFlexField.PrivateDescSeg1;
                    var formData = new FormData();
                    formData.formId = formId;
                    var dataDetails = new List<DataDetailsItem>();



                    //申请人
                    DataDetailsItem d1 = new DataDetailsItem();
                    d1.dataOptions = new List<DataOptionsItem> {new DataOptionsItem{
                        content = Context.LoginUser,
                        optionId = userinfo.Key,
                        type ="resource"
                    }};
                    d1.dataKey = "sqr";
                    dataDetails.Add(d1);

                    //申请部门
                    DataDetailsItem d2 = new DataDetailsItem();
                    d2.dataOptions = new List<DataOptionsItem> {new DataOptionsItem{
                        content="",
                        optionId= userinfo.Value,
                        type="department"
                    }};
                    d2.dataKey = "sqbm";
                    dataDetails.Add(d2);

                    //推送日期
                    DataDetailsItem d3 = new DataDetailsItem();
                    d3.content = DateTime.Now.Date.ToShortDateString();
                    d3.dataKey = "tsrq";
                    dataDetails.Add(d3);

                    //单据类型
                    DataDetailsItem d4 = new DataDetailsItem();
                    d4.content = holder.DocumentType.Name;
                    d4.dataKey = "djlx";
                    dataDetails.Add(d4);

                    //供应商名称
                    DataDetailsItem d5 = new DataDetailsItem();
                    d5.content = holder.Supplier.Name; ;
                    d5.dataKey = "gysmc";
                    dataDetails.Add(d5);

                    //单据日期
                    DataDetailsItem d6 = new DataDetailsItem();
                    d6.content = holder.BusinessDate.ToShortDateString();
                    d6.dataKey = "djrq";
                    dataDetails.Add(d6);

                    //币种
                    DataDetailsItem d7 = new DataDetailsItem();
                    d7.content = holder.TC.Name;
                    d7.dataKey = "bz";
                    dataDetails.Add(d7);


                    //流程编号
                    DataDetailsItem d8 = new DataDetailsItem();
                    d8.content = holder.DocNo;
                    d8.dataKey = "lcbh";
                    dataDetails.Add(d8);

                    //立账条件
                    DataDetailsItem d9 = new DataDetailsItem();
                    d9.content = holder.ConfirmTerm?.Name ?? "";
                    d9.dataKey = "lztj";
                    dataDetails.Add(d9);

                    //业务员
                    DataDetailsItem d10 = new DataDetailsItem();
                    d10.content = holder.PurOper?.Name ?? "";
                    d10.dataKey = "ywy";
                    dataDetails.Add(d10);

                    //部门
                    DataDetailsItem d11 = new DataDetailsItem();
                    d11.content = holder.PurDept?.Name ?? "";
                    d11.dataKey = "bm";
                    dataDetails.Add(d11);


                    //厂商价目表
                    PurPriceList purPriceList = PurPriceList.Finder.FindByID(holder.PriceList);
                    DataDetailsItem d12 = new DataDetailsItem();
                    d12.content = purPriceList?.Name ?? "";
                    d12.dataKey = "csjmb";
                    dataDetails.Add(d12);

                    //税组合
                    DataDetailsItem d13 = new DataDetailsItem();
                    d13.content = holder.TaxSchedule?.Name ?? "";
                    d13.dataKey = "szh";
                    dataDetails.Add(d13);

                    //收货原则
                    DataDetailsItem d14 = new DataDetailsItem();
                    d14.content = holder.ReceiptRule?.Name ?? "";
                    d14.dataKey = "shyz";
                    dataDetails.Add(d14);

                    //价格含税
                    DataDetailsItem d15 = new DataDetailsItem();
                    d15.content = holder.IsPriceIncludeTax ? "0" : "1";
                    d15.dataKey = "jghs";
                    dataDetails.Add(d15);


                    foreach (var line in holder.POLines)
                    {
                        //来源类别
                        string sql = $@" select dbo.F_GetEnumName('UFIDA.U9.PM.Enums.POSrcDocTypeEnum','{line.SrcDocType.Value}','zh-CN') POSrcDocTypeEnum";
                        DataAccessor.RunSQL(DataAccessor.GetConn(), sql, null, out DataSet ds);
                        string POSrcDocTypeEnum = ds.Tables[0].Rows[0]["POSrcDocTypeEnum"].ToString();
                        DataDetailsItem it1 = new DataDetailsItem();
                        it1.content = POSrcDocTypeEnum;
                        it1.dataIndex = line.DocLineNo / 10;
                        it1.dataKey = "lylb";
                        it1.subFormId = subFormId;
                        dataDetails.Add(it1);

                        //来源单号
                        DataDetailsItem it2 = new DataDetailsItem();
                        it2.content = line.SrcDocInfo?.SrcDocNo ?? "";
                        it2.dataIndex = line.DocLineNo / 10;
                        it2.dataKey = "lydh";
                        it2.subFormId = subFormId;
                        dataDetails.Add(it2);

                        //送货地址
                        DataDetailsItem it3 = new DataDetailsItem();
                        it3.content = DefineValue.Finder.Find($"ValueSetDef.Code = 'Z006' and Code = '{line.DescFlexSegments.PubDescSeg2}'")?.Name ?? "";
                        it3.dataIndex = line.DocLineNo / 10;
                        it3.dataKey = "shdz";
                        it3.subFormId = subFormId;
                        dataDetails.Add(it3);

                        //赠品
                        DataDetailsItem it4 = new DataDetailsItem();
                        it4.content = line.IsPresent ? "0" : "1";
                        it4.dataIndex = line.DocLineNo / 10;
                        it4.dataKey = "zp";
                        it4.subFormId = subFormId;
                        dataDetails.Add(it4);

                        //料号
                        DataDetailsItem it5 = new DataDetailsItem();
                        it5.content = line.ItemInfo.ItemID.Code;
                        it5.dataIndex = line.DocLineNo / 10;
                        it5.dataKey = "lh";
                        it5.subFormId = subFormId;
                        dataDetails.Add(it5);


                        //品名
                        DataDetailsItem it6 = new DataDetailsItem();
                        it6.content = line.ItemInfo.ItemID.Name;
                        it6.dataIndex = line.DocLineNo / 10;
                        it6.dataKey = "pm";
                        it6.subFormId = subFormId;
                        dataDetails.Add(it6);


                        //项目
                        DataDetailsItem it7 = new DataDetailsItem();
                        it7.content = line.Project?.Name ?? "";
                        it7.dataIndex = line.DocLineNo / 10;
                        it7.dataKey = "xm";
                        it7.subFormId = subFormId;
                        dataDetails.Add(it7);

                        //需求数量
                        DataDetailsItem it8 = new DataDetailsItem();
                        it8.content = line.ReqQtyTU.ToString();
                        it8.dataIndex = line.DocLineNo / 10;
                        it8.dataKey = "xqsl";
                        it8.subFormId = subFormId;
                        dataDetails.Add(it8);

                        //采购数量
                        DataDetailsItem it9 = new DataDetailsItem();
                        it9.content = line.PurQtyTU.ToString();
                        it9.dataIndex = line.DocLineNo / 10;
                        it9.dataKey = "cgsl";
                        it9.subFormId = subFormId;
                        dataDetails.Add(it9);

                        //采购单位
                        DataDetailsItem it10 = new DataDetailsItem();
                        it10.content = line.TradeUOM.Name;
                        it10.dataIndex = line.DocLineNo / 10;
                        it10.dataKey = "cgdw";
                        it10.subFormId = subFormId;
                        dataDetails.Add(it10);

                        //计价单位
                        DataDetailsItem it11 = new DataDetailsItem();
                        it11.content = line.PriceUOM.Name;
                        it11.dataIndex = line.DocLineNo / 10;
                        it11.dataKey = "jjdw";
                        it11.subFormId = subFormId;
                        dataDetails.Add(it11);

                        //交期
                        DataDetailsItem it12 = new DataDetailsItem();
                        it12.content = line.POShiplines[0]?.DeliveryDate.ToShortDateString() ?? "";
                        it12.dataIndex = line.DocLineNo / 10;
                        it12.dataKey = "jq";
                        it12.subFormId = subFormId;
                        dataDetails.Add(it12);

                        //最终价原币
                        DataDetailsItem it13 = new DataDetailsItem();
                        it13.content = line.FinallyPriceTC.ToString();
                        it13.dataIndex = line.DocLineNo / 10;
                        it13.dataKey = "zzjyb";
                        it13.subFormId = subFormId;
                        dataDetails.Add(it13);

                        //价税合计原币
                        DataDetailsItem it14 = new DataDetailsItem();
                        it14.content = line.TotalMnyTC.ToString();
                        it14.dataIndex = line.DocLineNo / 10;
                        it14.dataKey = "sjhjyb";
                        it14.subFormId = subFormId;
                        dataDetails.Add(it14);

                        //未税金额原币
                        DataDetailsItem it15 = new DataDetailsItem();
                        it15.content = line.NetMnyTC.ToString();
                        it15.dataIndex = line.DocLineNo / 10;
                        it15.dataKey = "wsjeyb";
                        it15.subFormId = subFormId;
                        dataDetails.Add(it15);

                        //税额原币
                        DataDetailsItem it16 = new DataDetailsItem();
                        it16.content = line.TotalTaxTC.ToString();
                        it16.dataIndex = line.DocLineNo / 10;
                        it16.dataKey = "seyb";
                        it16.subFormId = subFormId;
                        dataDetails.Add(it16);

                        //存储地点
                        DataDetailsItem it17 = new DataDetailsItem();
                        it17.content = line.POShiplines[0]?.Wh?.Name ?? "";
                        it17.dataIndex = line.DocLineNo / 10;
                        it17.dataKey = "ccdd";
                        it17.subFormId = subFormId;
                        dataDetails.Add(it17);

                        //贸易路径
                        DataDetailsItem it18 = new DataDetailsItem();
                        it18.content = line.TradePath?.Name ?? "";
                        it18.dataIndex = line.DocLineNo / 10;
                        it18.dataKey = "mylj";
                        it18.subFormId = subFormId;
                        dataDetails.Add(it18);

                    }

                    formData.dataDetails = dataDetails;
                    dto.formData = formData;
                    var Content = JsonConvert.SerializeObject(dto);
                    httpHelper.Content = Content.Remove(Content.Length - 2, 2) + $@" }},""seniorFormParam"": {{""subFormMatchFields"": {{ ""{subFormId}"": {{""cover"": true,""subFormMatchMore"": ""ZERO"",""subFormNoMatch"": ""ADD""}}}}}}, ""isNewFormData"": true}}";

                    var result = JObject.Parse(httpHelper.HttpPosts("POST"));
                    if (result["message"]["errmsg"].ToString() != "success")
                    {
                        throw new Exception(result["message"]["errmsg"].ToString());
                    }
                }

            }
        }
    }
}
